﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TetrisGame
{
    class Drawer
    {
        public Drawer()
        {
            Console.CursorVisible = false;
        }

        public void DrawObjectList(IEnumerable<Block> figure, GameField gamefield)
        {
            foreach (var block in figure)
            {
                DrawObject(block,gamefield);
            }
        }

        public void DrawObject(Block block, GameField gamefield) //Separation of logic. It's better to move checks (game field borders) to logic
        {
            Console.ForegroundColor = block.Color;
            if (block.Y >= gamefield.Y)
            {
                Console.SetCursorPosition(block.X, block.Y);
                Console.Write("0");
            }
        }

        public void DrawFrameAndSpaces(GameField field, char symbol)
        {
            int frameX = field.X - 1;
            int frameY = field.Y;
            int frameHeight = field.Height;
            int frameWidth = field.Width + 1;

            for (int i = 0; i <= frameHeight; i++)
            {
                Console.ForegroundColor = ConsoleColor.Gray;
                Console.SetCursorPosition(frameX, frameY + i);
                for (int j = 0; j <= frameWidth; j++)
                {
                    if (i == frameHeight)
                        Console.Write(symbol);
                    else if (j == 0 || j == frameWidth)
                        Console.Write(symbol);
                    else Console.Write(" ");
                }
                Console.WriteLine("\n");
            }
        }

        public void DrawScoreAndMessage(GameField field, string message, int score, int speed)
        {
            Console.ForegroundColor = ConsoleColor.Gray;
            Console.SetCursorPosition(field.X + field.Width + 5, field.Y - 1);
            Console.Write("Score: {0}", score);
            Console.SetCursorPosition(field.X + field.Width + 5, field.Y + 1);
            Console.Write("Speed: {0}", speed);
            Console.SetCursorPosition(field.X + field.Width + 5, field.Y + 3);
            Console.Write(message);

        }
    }
}
